package com.hexu.event.view;

import com.hexu.event.bean.CommentBean;
import com.hexu.event.entity.Comment;
import com.hexu.event.util.StageUtil;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;

import java.util.ArrayList;
import java.util.List;

public class CommentTableView {
    //显示评论的表
    public static void viewCommentContent(int commentNumber, List<Comment> commentsList) {

        List<CommentBean>commentBeanList = new ArrayList<>();

        TableView<CommentBean> table = new TableView<>();

        HBox hb = new HBox();

        for(int i = 0;i<commentNumber;i++){
            //添加评论信息
            commentBeanList.add(  new CommentBean(commentsList.get(i).getAttractionsName(),commentsList.get(i).getUserPhoneNumber(),
                    commentsList.get(i).getContent(),commentsList.get(i).getCommentTime())
            );
        }
        //转化成表可存放的数据
        final ObservableList<CommentBean> data =
                FXCollections.observableArrayList(
                        commentBeanList
                );


        //景点名字
        //列的数据类型
        TableColumn<CommentBean,String> nameCol =
                new TableColumn<>("景点名字");
        //设置出是最小宽度
        nameCol.setMinWidth(100);
        nameCol.setCellValueFactory(
                new PropertyValueFactory<>("attractionsName"));
        //用户手机号码
        TableColumn<CommentBean, String> phoneNumberCol =
                new TableColumn<>("手机号码");
        phoneNumberCol.setMinWidth(125);
        phoneNumberCol.setCellValueFactory(
                new PropertyValueFactory<>("phoneNumber"));
        //评论内容
        TableColumn<CommentBean, String> contentCol = new TableColumn<>("评论内容");
        contentCol.setMinWidth(200);
        contentCol.setCellValueFactory(
                new PropertyValueFactory<>("content"));
        //评论时间
        TableColumn<CommentBean,String> commentTimeCol = new TableColumn<>("评论时间");
        commentTimeCol.setMinWidth(150);
        commentTimeCol.setCellValueFactory(
                new PropertyValueFactory<>("commentTime"));

        //接收信息
        table.setItems(data);
        //把数据放在相应列里
        table.getColumns().addAll(nameCol,phoneNumberCol, contentCol,commentTimeCol);

        hb.setPadding(new Insets(10, 0, 0, 10));
        hb.getChildren().add(table);
        StageUtil.showStage(new Stage(),new Scene(hb),550,600,"评论信息",false);
    }
}
